package com.sysd.imgboard.controller;

import java.util.logging.Logger;
import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.datastore.Datastore;

import com.sysd.imgboard.meta.ChildMeta;
import com.sysd.imgboard.meta.ThreadMeta;
import com.sysd.imgboard.model.Child;
import com.sysd.imgboard.model.Thread;
import com.sysd.imgboard.util.ForwardUtil;

public class WriteController extends Controller {

    @SuppressWarnings("unused")
    private static final Logger logger = Logger.getLogger(WriteController.class.getName());

    @Override
    public Navigation run() {
        
        long threadId = 3L;
        
        ChildMeta cm = new ChildMeta();
        long count = (long)Datastore.query(cm)
            .filter(cm.threadId.equal(threadId))
            .countQuickly();
        if(count < 1000){
            count ++;
            Child c = new Child();
            c.setCategory("test");
            c.setThreadId(threadId);
            c.setChildId(count);
            Datastore.put(c);
        }

        
        return forward(ForwardUtil.forwardJsp("write.jsp"));
    }
}
